package org.cpar.compiler;

import java.util.List;

import org.antlr.runtime.Token;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.Tree;

public class CPARNode extends CommonTree {

	public CPARNode(CPARNode base) {
		super(base);
	}

	public CPARNode() {
	}

	public CPARNode(Token token) {
		super(token);
	}

	public CPARNode getChildNode(int i) {
		return (CPARNode) getChild(i);
	}

	@SuppressWarnings("unchecked")
	public List<CPARNode> getChildrenNodes() {
		return (List<CPARNode>) getChildren();
	}

	public void accept(ICodeWriter writer) {
		if (getChildCount() == 0)
			return;

		for (Object oc : getChildren())
			((CPARNode) oc).accept(writer);
	}

	@Override
	public boolean isNil() {
		return token == null;
	}

	@Override
	public Tree dupNode() {
		return new CPARNode(this);
	}

	public void clearChildren() {
		for (int i = 0; i < getChildCount(); i++)
			deleteChild(i);
	}
}
